#!/usr/bin/python3
# -*- coding: utf-8 -*-

import allure
from playwright.sync_api import Page

from models.base_page import BasePage


class NetworkAclPage(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)
        self.route = "network_access_control"
        self.sub_route = "network_acls"

    def check_network_acl_page_user_guide_element_to_be_visible(self):
        """检查使用指南元素是否可见"""
        with allure.step("检查NetworkAclPage:使用指南元素是否可见"):
            self.expect.to_be_visible(self.page.locator(".intro"))  # 使用指南栏目
            self.expect.to_be_visible(self.page.get_by_text("使用指南"))
            self.expect.to_be_visible(self.page.get_by_text("收起"))
            self.expect.to_be_visible(self.page.locator(".svg-icon > use"))
            self.expect.to_contain_text(self.page.locator("#console"),
                                        "网络 ACL 是私有网络（Vxnet）的进出流量控制表。"
                                        "您可以在这里创建和配置 ACL 规则， ACL 规则中声明了哪些流量可以进、出私有网络，"
                                        "通过与私有网络关联的出方向、入方向规则控制出入私有网络的数据流量。")

    def check_network_acl_page_table_element_to_be_visible(self):
        """检查工具栏及table是否可见"""
        with allure.step("检查NetworkAclPage:工具栏及table是否可见"):
            self.expect.to_be_visible(self.page.locator(".table-toolbar"))
            self.expect.to_be_visible(self.page.get_by_role("link", name="G", exact=True))
            self.expect.to_be_visible(self.page.locator("a").filter(has_text="创建"))
            self.expect.to_be_visible(self.page.locator("a").filter(has_text="复制"))
            self.expect.to_be_visible(self.page.locator("input[type=\"text\"]"))
            self.expect.to_be_visible(self.page.get_by_placeholder(" "))
            self.expect.to_be_visible(self.page.get_by_role("combobox"))